import * as THREE from "three";

const LightStripShader1 = {
  shaderID: 'LightStripShader1',

  uniforms: {
    'iTime': { value: 1.0 },
    'color': { value: new THREE.Color('#ffffff') },
  },

  vertexShader: /* glsl */`
  varying vec2 vUv;
  
  void main() {
    vUv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }`,

  fragmentShader: /* glsl */`
	uniform float iTime;
	uniform vec3 color;
  varying vec2 vUv;
  const float PI = 3.1415926;
  const float PI_2 = 2.0 * PI;
 
  void main() {
    float y = 0.8;
    float y2 = vUv.y ;

    float x = y2 - y ;
    float s = sin(iTime*0.3);
    vec3 colorHalf = vec3(0.15);
    vec3 white = vec3(1.0);
    vec3 colorBack1 = mix(vec3(0.0), colorHalf, pow(cos(PI * x / 2.0), 8.5) );
    vec3 colorFront1 = mix(vec3(0.0), white, 1.0 - max(0.0, abs(x) * 10.0 ) );
    vec3 color1 = max(colorFront1, colorBack1);

    float x2 = y2 - 0.25 ;
    vec3 colorBack2 = mix(vec3(0.0), colorHalf, pow(cos(PI * x2 / 2.0), 8.5) );
    vec3 colorFront2 = mix(vec3(0.0), white, 1.0 - max(0.0, abs(x2) * 10.0 ) );
    vec3 color2 = max(colorFront2, colorBack2);
    float a1 = 0.5 - 0.5*s;
    float a2 = 1.0 - a1;
    vec4 clr1 = vec4(color1, 1.0) * vec4(a1);
    vec4 clr2 = vec4(color2, 1.0) * vec4(a2);
    // vec4 colorMerged = clr1 + clr2;
    vec4 colorMerged = max(clr1, clr2);
    // if (a2 > 0.55) {
    //   colorMerged = clr2;
    // } else if (a1 > 0.55) {
    //   colorMerged = clr1;
    // }
    gl_FragColor = colorMerged * vec4(color, 1.0);
  }
`
}

export default LightStripShader1;
